﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using Routine.Api.Entities;
using Routine.Api.Models;

namespace Routine.Api.Profiles
{
    public class EmployeeProfile:Profile
    {
        public EmployeeProfile()
        {
            CreateMap<Employee, EmployeeDto>()  //将Employee映射到EmployeeDto;
                .ForMember(dest => dest.Name,
                opt => opt.MapFrom(src => $"{src.LastName}{src.FirstName}"))//映射姓名；
                .ForMember(dest => dest.GenderDisplay,
                opt => opt.MapFrom(src => src.Gender.ToString()))//性别转化为字符串；
                .ForMember(dest => dest.Age,
                opt => opt.MapFrom(src => DateTime.Now.Year - src.DateOfBirth.Year));//映射年龄；


            CreateMap<EmployeeAddDto, Employee>();  //完成映射，属性基本相同。不用更改。
            CreateMap<EmployeeUpdateDto, Employee>();
            CreateMap<Employee,EmployeeUpdateDto >();//这个映射是反过来的；
        }
    }
}
